package com.example.exam3;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Switch;

import androidx.appcompat.app.AppCompatActivity;

public class exam3 extends AppCompatActivity implements View.OnClickListener {
    ImageView ivApple;
    ImageView ivBoy;
    Button btnFitCenter;
    Button btnCenterCrop;
    Button btnCenterInside;
    Button btnCenter;
    Button btnFitXY;
    Button btnFitStart;
    Button btnFitEnd;
    Switch stLight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exam3);
        ivApple = findViewById(R.id.iv_apple);
        ivBoy = findViewById(R.id.iv_boy);
        stLight = findViewById(R.id.st_light);
        stLight.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (!isChecked) {
                ivBoy.setImageResource(R.drawable.light);
            } else {
                ivBoy.setImageResource(R.drawable.dark);
            }
        });
        //fit_center
        btnFitCenter = findViewById(R.id.btn_fit_center);
        btnFitCenter.setOnClickListener(this);
        //fit_crop
        btnCenterCrop = findViewById(R.id.btn_center_crop);
        btnCenterCrop.setOnClickListener(this);
        //center_inside
        btnCenterInside = findViewById(R.id.btn_center_inside);
        btnCenterInside.setOnClickListener(this);
        //center
        btnCenter = findViewById(R.id.btn_center);
        btnCenter.setOnClickListener(this);
        //fit_xy
        btnFitXY = findViewById(R.id.btn_fit_xy);
        btnFitXY.setOnClickListener(this);
        //fit_start
        btnFitStart = findViewById(R.id.btn_fit_start);
        btnFitStart.setOnClickListener(this);
        //fit_end
        btnFitEnd = findViewById(R.id.btn_fit_end);
        btnFitEnd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_fit_center:
                ivApple.setScaleType(ImageView.ScaleType.FIT_CENTER);
                break;
            case R.id.btn_center_crop:
                ivApple.setScaleType(ImageView.ScaleType.CENTER_CROP);
                break;
            case R.id.btn_center_inside:
                ivApple.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                break;
            case R.id.btn_center:
                ivApple.setScaleType(ImageView.ScaleType.CENTER);
                break;
            case R.id.btn_fit_xy:
                ivApple.setScaleType(ImageView.ScaleType.FIT_XY);
                break;
            case R.id.btn_fit_start:
                ivApple.setScaleType(ImageView.ScaleType.FIT_START);
                break;
            case R.id.btn_fit_end:
                ivApple.setScaleType(ImageView.ScaleType.FIT_END);
                break;
            default:
                break;
        }
    }
}
